<template>
  <div>
    <el-table :data="tableData" height="500" style="width: 100%">
      <el-table-column label="用户名" width="180">
        <template slot-scope="scope">
          <el-popover trigger="hover" placement="top">
            <p>姓名: {{ scope.row.friendname }}</p>
            <p>ID: {{ scope.row.friendid }}</p>
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{ scope.row.friendname }}</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="success"
            style="width: 80px"
            @click="handleAddOrRefuse(scope.$index, scope.row,1)"
            v-if="scope.row.isaccept==0"
            >同意</el-button
          >
          <el-button
            size="mini"
            type="danger"
            style="width: 80px"
            @click="handleAddOrRefuse(scope.$index, scope.row,2)"
            v-if="scope.row.isaccept==0"
            >拒绝</el-button
          >
          <el-button
            size="mini"
            type="danger"
            style="width: 80px"
            v-if="scope.row.isaccept==2"
            disabled
            >已拒绝</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>


<script>
export default {
  created() {
    this.getApply();
  },
  data() {
    return {
      tableData: [],
    };
  },
  methods: {
    getApply(){
      this.$http
      .get(`/system/tbApply/getApply?friendid=${JSON.parse(localStorage.getItem("userInfo")).userid}`)
      .then(res=>{
        this.tableData=res.data.data
        console.log(this.tableData)
      })
    },
    handleAddOrRefuse(index,row,number){
      console.log(row)
      this.$http
      .post(`/system/tbApply/addOrRefuse`,{userid:row.userid,friendid:row.friendid,isaccept:number})
      .then(res=>{
        if(res.data.code==200){
          this.$notify({
          title: '成功',
          message: '成功',
          type: 'success'
        });
        location.reload()
        }
      })
    }
  },
};
</script>